atopProc  PROC NEAR32
; Convert ASCII string at to 10 byte BCD number
; parameter 1: ASCII string address    parameter 2: BCD number address
; null-terminated ource string consists only of ASCII codes for digits,
; author:  R. Detmer     revised: 5/98
          push ebp       ; establish stack frame
          mov  ebp, esp
          push esi                   ; save registers
          push edi
          push eax
          push ecx
          mov  esi, [ebp+12]         ; source address
          mov  edi, [ebp+8]          ; destination address          
          mov  DWORD PTR [edi], 0    ; zero BCD destination
          mov  DWORD PTR [edi+4], 0
          mov  WORD PTR [edi+8], 0
; find length of source string and move ESI to trailing null
          mov  ecx, 0                ; count := 0
while1:   cmp  BYTE PTR [esi], 0     ; while not end of string (null)
          jz   endwhile1
          inc  ecx                   ; add 1 to count of characters
          inc  esi                   ; point at next character
          jmp  while1                ; check again
endwhile1:
; process source characters a pair at a time
while2:   cmp  ecx, 0                ; while count > 0
          jz   endwhile2
          dec  esi                   ; point at next ASCII byte from right
          mov  al, BYTE PTR [esi]    ; get byte
          and  al, 00001111b         ; convert to BCD digit
          mov  BYTE PTR [edi], al    ; save BCD digit
          dec  ecx                   ; decrement count
          jz   endwhile2             ; exit loop if out of source digits
          dec  esi                   ; point at next ASCII byte from right
          mov  al, BYTE PTR [esi]    ; get byte
          shl  al, 4                 ; shift to left and convert to digit
          or   BYTE PTR [edi], al    ; combine with other BCD digit
          dec  ecx                   ; decrement count
          inc  edi                   ; point at next destination byte
          jmp  while2                ; repeat for all source characters
endwhile2:
          pop ecx                    ; restore registers
          pop eax
          pop esi
          pop edi
          pop ebp
          ret 8                      ; return, removing parameters
atopProc  ENDP

